package com.woniu.controller;

import com.woniu.domain.User;
import com.woniu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "user表增删改查")
@RestController
@RequestMapping("user")
@EnableEurekaClient
@MapperScan(basePackages = "com.woniu.mapper")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("查询所有user")
    @GetMapping
    public List<User> selectAllUser(){
        List<User> list = userService.list();
        return list;
    }

    @ApiOperation("根据id修改user")
    @PutMapping
    boolean updateUserById(@RequestBody User user){
        boolean b = userService.updateById(user);
        return b;
    }

    @ApiOperation("添加一个user")
    @PostMapping
    boolean insertUser(@RequestBody User user){
        boolean b = userService.save(user);
        return b;
    }

    @ApiOperation("根据id删除一个user")
    @DeleteMapping("/{id}")
    boolean deleteUserById(@PathVariable Integer id){
        boolean b = userService.removeById(id);
        return b;
    }

}
